package com.springboot.file.util.easyexcel.registrar;

import com.springboot.file.util.easyexcel.EasyExcelUtil;
import com.springboot.file.util.easyexcel.provider.ExportProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 导出提供者自动注册类
 */
@Slf4j
@Configuration
public class ExportProviderRegistrar {

    @Resource
    private EasyExcelUtil easyExcelUtil;

    @Resource
    private ApplicationContext applicationContext;

    @PostConstruct
    public void registerExportProviders() {
        // 显式转换泛型类型
        @SuppressWarnings("unchecked")
        Map<String, ExportProvider<?>> providerBeans = (Map<String, ExportProvider<?>>) (Map<?, ?>) applicationContext.getBeansOfType(ExportProvider.class);
        log.info("获取到的 ExportProvider 类型的 Bean 数量: {}", providerBeans.size());
        for (ExportProvider<?> provider : providerBeans.values()) {
            easyExcelUtil.registerExportProvider(provider);
        }
    }
} 